package com.ship.dispatch.service.fob.impl;
/**
 *@title SpFobFileRecordServiceImpl
 *@description
 *@author yl
 *@create 2023/12/15 0015
 */

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ship.common.business.service.impl.BaseServiceImpl;
import com.ship.dispatch.bean.fob.SpFobFileRecord;
import com.ship.dispatch.mapper.fob.SpFobFileRecordMapper;
import com.ship.dispatch.service.fob.SpFobFileRecordService;
import com.ship.dispatch.service.fob.SpFobJsfhccbItemsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SpFobFileRecordServiceImpl extends BaseServiceImpl<SpFobFileRecordMapper, SpFobFileRecord> implements SpFobFileRecordService {

    @Override
    public void deleteOtherFileRecor(Long id, List<String> fiels) {
        if(fiels.size()>0){

            SpFobFileRecord record = new SpFobFileRecord();
            record.setIsDelete(1);
            this.baseMapper.update(record,new LambdaQueryWrapper<SpFobFileRecord>().in(SpFobFileRecord::getId,fiels));
            this.baseMapper.delete(new LambdaQueryWrapper<SpFobFileRecord>().eq(SpFobFileRecord::getServiceId,id).notIn(SpFobFileRecord::getId,fiels).isNull(SpFobFileRecord::getOrderDetailId));
        }else {
            this.baseMapper.delete(new LambdaQueryWrapper<SpFobFileRecord>().eq(SpFobFileRecord::getServiceId,id).isNull(SpFobFileRecord::getOrderDetailId));
        }
    }

    @Override
    public SpFobFileRecord selectByServiceAndTemplate(Long serviceId, String templateId) {
        SpFobFileRecord spFobFileRecord = this.baseMapper.selectOne(new LambdaQueryWrapper<SpFobFileRecord>().eq(SpFobFileRecord::getServiceId,serviceId).eq(SpFobFileRecord::getTemplateId,templateId).last("limit 1"));
        return spFobFileRecord;
    }

    @Override
    public List<SpFobFileRecord> queryShipConsumptionList(Long id) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("ship_property_id",id);
        List<SpFobFileRecord> list = baseMapper.selectList(queryWrapper);
        return list;
    }

    @Override
    public boolean deleteShipConsumptionById(Long id) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("id",id);
        int i = baseMapper.deleteById(id);
        if (i==1){
            return true;
        }
        return false;
    }

    @Override
    public SpFobFileRecord queryRecordById(String fileId) {
        return baseMapper.selectById(fileId);
    }

}
